package cn.bdqn.controller.reportForms;


import cn.bdqn.pojo.reportForms.StatisByDay;
import cn.bdqn.service.reportForms.UserStatisService;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import lombok.experimental.Accessors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.*;

@RestController
@RequestMapping("/api/statis")
public class StatisDataController {

    @Autowired
    private UserStatisService userStatisService;


    @ResponseBody
    @PostMapping("/chats")
    public Map getStatisQuestion(@RequestBody String type) {


        // jsonString转换成Map
        Map<String, String> jsonMap = JSON.parseObject(type, new TypeReference<HashMap<String, String>>() {
        });
        System.out.println("jsonMap: " + jsonMap.toString());
        String cusType = jsonMap.get("type");
        System.out.println("自定义类型: " + cusType);
        List<StatisByDay> data = null;
        if (cusType.equals("day")) {
            data = userStatisService.queryStatisByDay();
        } else if (cusType.equals("week")) {
            data = userStatisService.queryStatisByWeek();
        } else if (cusType.equals("mound")) {
            data = userStatisService.queryStatisByMonuth();
        }

        //   <el-dropdown-item command="day">每天</el-dropdown-item>
        // <el-dropdown-item command="week">每周</el-dropdown-item>
        // <el-dropdown-item command="mound">每月</el-dropdown-item>

        Map map = new HashMap();
        map.put("data", data);
        map.put("msg", "成功");

        return map;

    }

    @ResponseBody
    @PostMapping("/order")
    public Map getStatisOrder(@RequestBody String type) {
        // jsonString转换成Map
        Map<String, String> jsonMap = JSON.parseObject(type, new TypeReference<HashMap<String, String>>() {
        });
        System.out.println("jsonMap: " + jsonMap.toString());
        String cusType = jsonMap.get("type");
        System.out.println("自定义类型: " + cusType);
        List<StatisByDay> data = null;

        data = userStatisService.queryStatisOrderBy(cusType);

        Map map = new HashMap();
        map.put("data", data);
        map.put("msg", "成功");

        return map;
    }

    @ResponseBody
    @PostMapping("/orderPrice")
    public Map getStatisOrderPrice(@RequestBody String type) {
        // jsonString转换成Map
        Map<String, String> jsonMap = JSON.parseObject(type, new TypeReference<HashMap<String, String>>() {
        });
        System.out.println("jsonMap: " + jsonMap.toString());
        String cusType = jsonMap.get("type");
        System.out.println("自定义类型: " + cusType);
        List<StatisByDay> data = null;

        data = userStatisService.queryStatisOrderPriceBy(cusType);

        Map map = new HashMap();
        map.put("data", data);
        map.put("msg", "成功");

        return map;
    }
}
